package com.loren.demo14.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {

    @GetMapping("/hello")
    public String hello() {
        return "Hello world";
    }

    @GetMapping("/info")
    public Object loginInfo(Authentication authentication) {
        return authentication.getPrincipal();
    }

    @GetMapping("/auth1")
    @PreAuthorize("hasAuthority('admin')")
    public String auth1() {
        return "hello admin";
    }

    @GetMapping("/auth2")
    @PreAuthorize("hasAuthority('super')")
    public String auth2() {
        return "hello super";
    }
}